-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: unsurprising module imports #18
Conversation
I think your wording is slightly...antagonistic, which doesn't help your case. (Some of us, at least, find the current system quite logical.) This discussion is not helped by the lack of a good understanding of the full details of our name resolution algorithm, but I fear there may be some interaction. This proposal is certainly missing some details. For example, if I have "somerandomfile.rs" in my directory tree that is never used, is it going to be compiled? You point at Python for precedent, and in that case the answer is no: files are only processed once they are imported by someone. In that case, we'd be unable to construct a full module tree without processing imports (processing imports essentially becomes intertwined with constructing the module tree). I am not sure how this affects the (not generally well understood) name resolution algorithm, but it's something to work out. In general, I am reluctant to accept any change to the module system that does not include a reasonably complete specification of how name resolution should work (and we most certainly need to write such a description for the current system as well!). There are numerous complexities to consider. |
If I'm somewhat antagonistic, it's because people keep insisting that there is absolutely nothing wrong, despite the fact that this is probably the 2nd most common thing newcomers get confused about (after lifetime errors). The current system is logical to some subset of people who understand it. I proposed a system that, I believe, is logical to people even before they understand all the details.
I'm not intimately familiar with the technical details of name resolution, but my understanding is that (before or after my proposal) an object is in scope if one of:
And a method is in scope if its trait is
No. Some of the alternatives might do this (perhaps under the "java-style" alternative, though Java doesn't go that far); but I actually count this as an argument against
Given that
Since Rust doesn't have ADL (thank Turing for traits!), I don't see what the complexities are. Other than whether an unqualified path is taken as absolute or relative by default (which would be an argument for requiring absolute paths to start with |
This doesn't seem safe to me because a module that contains only trait implementations will then never be picked up.
Traits/impls above and how you deal with multiple namespaces (types versus values), whether it's allowed to chain an import off another one ( |
You just use the
I'm a fan of forbidding the same identifier from being used in multiple namespaces. IMO the only reason people even think about it is because of compatibility with things like Is there anyone to defend allowing it?
Assuming the relative import model, that would be the same as (with the absolute import model, (by "equivalent" I ignore the fact that it's also making
Why not? Python just follows the "if module has already started being import it, return immediately" approach - and since Rust doesn't have to execute as it goes, it avoids the problem to beware of when writing python code. (I mentioned this and the other approach on line 87 "To avoid cycles during compilation,") |
We have to have the same identifier in multiple namespaces. Consider newtype structs: the name of the constructor is the name of the type. |
Sure, but in that case, it's the same "object" that can be used in more than one way. As a single object, it can either be in scope or not in scope. |
I don't see much of a difference between that and the current system, except that it seems like that would make it inconsistent as to when |
It's quite simple. You use This is how everybody coming into Rust expects things to Just Work. Choosing exactly one place to put the |
But sometimes you want to specify that you want to bring this module into On Tuesday, April 1, 2014, o11c notifications@github.com wrote:
|
For modules, the following cases exist:
For cases 2 and 3 there, it makes sense that |
Closing, not accepted. Assigned RFC 9 and moved to the 'rejected' folder. Reasoning is as stated during review. Thank you. |
This is an update of my proposed resolution for old-style RFC rust-lang/rust#11745